<?php
	class Comentarios extends Zend_Db_Table_Abstract
	{
		protected $_primary = 'id_comentario';
		protected $_name = 'comentario';
		
		protected $_referenceMap = array
		(
			'Noticia'    =>  array
			(
	            'columns'       =>  'id_noticia',
	            'refTableClass' =>  'Noticias',
	            'refColumns'    =>  'id_noticia'
			)
		);
		
		protected static $_instance = null;
		
        public static function getInstance()
        {
            if (null === self::$_instance) 
			{
                self::$_instance = new self();
            }
            return self::$_instance;
        }
		
		public static function getComentarios ($id = null)
		{
			$table = self::getInstance();
            $select = $table->select();
			$select->setIntegrityCheck(false);
			$select->from($table);
			
			$select->joinLeft('usuario', 'usuario.id_user = comentario.id_user',
				array 
				(
					'user' 	=> 'usuario.user',
				)
			);
			
			$select->where('id_noticia = ?', $id);
			
            return $table->fetchAll($select);
		}
		
		/* Metodo Magico. iria en el controller
		//INSTRUCCIONES PARA CAPTURAR LOS COMENTARIOS CORRESPONDIENTES A LA NOTICIA SELECCIONADA.
		$news = new Noticias();
		$accountsRowset = $news->find($id);
		$comentarios = $accountsRowset->current();
		$this->view->comments = $comentarios->findComentariosByNoticia('News');
		*/
	}